/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __X_ERRNO_H__
#define __X_ERRNO_H__

/* includes (standard library, system) ---------------------------------------*/
#include <stdint.h>
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
/* includes (local) ----------------------------------------------------------*/
#include <x_config.h>
#include <x_module.h>

#ifdef CONFIG_OS_PONY
#include <k_errno.h>
#else
#include <errno.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/

/*
 * kernel specific errno
 *
 * the errno format:
 *
 * +-----+-----+
 * | mid | err |
 * +-----+-----+
 *    |     |
 *    |     \
 *    \      `-- 8-bit error number
 *     `-------- 8-bit module id
 */

#define ERRNO_JOIN(mid, err) ((((uint32_t)mid & 0xff) << 8) | (((uint32_t)err & 0xff) << 0))

/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __X_ERRNO_H__ */
